import { TypedStorageDecoder, TypedStorageEncoder, TypedStorageOptions } from "@nsb/common-tools";

export enum LayoutType {
  min = 0,
  sidebar_main = 0,
  topbar_main = 1,
  max = 1
}
export const layoutTypeClassName: Record<LayoutType, string> = {
  [LayoutType.sidebar_main]: 'app_sidebar_main',
  [LayoutType.topbar_main]: 'app_topbar_main',
}
const encoder: TypedStorageEncoder<LayoutType | null> = data => '' + data;
const decoder: TypedStorageDecoder<LayoutType | null> = raw => {
  const num = Number(raw)
  if (Number.isNaN(num)) return LayoutType.min;
  else if (num < LayoutType.min) return LayoutType.min;
  else if (num > LayoutType.max) return LayoutType.max;
  else return num
}
export const layoutTypeOptions: TypedStorageOptions<LayoutType | null> = {
  defaultValue: LayoutType.sidebar_main,
  encoder,
  decoder,
}
